/*
 * Copyright (C), 2014-2015, 联创车盟汽车服务有限公司
 * FileName: UserService.java
 * Author:   Administrator
 * Date:     2015年1月31日 下午2:27:35
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>    <time>    <version>    <desc>
 * 修改人姓名        修改时间        版本号        描述
 */
package com.linkage.service.consumer;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.linkage.pojo.consumer.User;
import com.linkage.repository.consumer.UserRepository;

/**
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author Administrator
 *
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;
    
    public void saveUser(User user){
        this.userRepository.saveUser(user);
    }
    
    public User getOneUserById(Integer userId){
        return this.userRepository.getOneUserById(userId);  
    }
    
    public User getOneUserByLoginName(String loginName){
        return this.userRepository.getOneUserByLoginName(loginName);
    }
    
    public List<User> listAllUser(){
        return this.userRepository.listAllUser();
    }
    
    public boolean register(User user){
        User t_user=new User();
        t_user=this.userRepository.getOneUserByLoginName(user.getLoginName());
        
        if(t_user!=null){
            return false;
        }
        else{
            
            this.userRepository.saveUser(user);
            return true;
        }
    }
    
    public void editProfile(User user){
        this.userRepository.editprofile(user);
        
    }

    public boolean login(@Param("password") String password ,@Param("loginName") String loginName){
        
        User user=new User();
        user=this.userRepository.getOneUserByLoginName(loginName);
        if(user==null||!user.getPassword().equals(password)){
            return false;
        }
        return true;
        
    }

    public boolean selectUserByLoginName(String loginName){
        
        if(this.userRepository.getOneUserByLoginName(loginName)!=null){
            return true;
        }
        else{
            return false;
        }
        
    }

    public boolean selectUserByPassword(String password){
         
        if(this.userRepository.selectUserByPassword(password)!=null){
            return true;
        }
        else{
            return false;
        }
    }
    
    public void register(String userName, String password, String loginName, String email){
        User user=new User();
        user.setAccount(100);
        user.setEmail(email);
        user.setLoginName(loginName);
        user.setPassword(password);
        Date date=new Date();
        user.setRegisterTime(date);
        user.setUserName(userName);
        
        this.userRepository.saveUser(user);
        
    }


}
